<!--
 * Description: FD待分配页面
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Qiuxue.Wu
 * Date: 2020/05/20 16:39
-->

<template>
  <BaseWrap>
    <!-- 查询条件 -->
    <BaseFunc
      drawer-size="600"
      :is-requesting="isRequesting"
      :query-form="queryForm"
      :visible.sync="advanceOptionDrawer"
      @query="query"
    >
      <!--抽屉内部查询表单-->
      <template>
        <el-form class="g-advance-drawer-form" label-width="100px" :model="queryForm" size="mini">
          <el-row>
            <!--rfqId-->
            <el-col :span="6">
              <el-form-item label="RFQ ID">
                <el-input v-model="queryForm.rfqId" clearable />
              </el-form-item>
            </el-col>

            <!--rfq名称-->
            <el-col :span="6">
              <el-form-item label="RFQ名称">
                <el-input v-model="queryForm.rfqName" clearable />
              </el-form-item>
            </el-col>
            <!--solution-->
            <el-col :span="6">
              <el-form-item label="Solution">
                <el-input v-model="queryForm.solution" clearable />
              </el-form-item>
            </el-col>

            <!--tempmodel-->
            <el-col :span="6">
              <el-form-item label="Temp-Model">
                <el-input v-model="queryForm.tempModel" clearable />
              </el-form-item>
            </el-col>
            <!--tempModelNumber-->
            <el-col :span="6">
              <el-form-item label="TempModelNumber">
                <el-input v-model="queryForm.tempModelNumber" clearable />
              </el-form-item>
            </el-col>
            <!-- state列 -->
            <el-col :span="6">
              <el-form-item label="进度状态">
                <el-select
                  v-model="queryForm.state"
                  clearable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['dict/dictOptions']('SolutionStatus')"
                    :key="item.code"
                    :label="item.value"
                    :value="item.code"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <!-- 是否检查列 -->
            <el-col :span="6">
              <el-form-item label="检查状态">
                <el-select
                  v-model="queryForm.checkState"
                  clearable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option label="未检查" :value="null" />
                  <el-option label="未通过" :value="0" />
                  <el-option label="已通过" :value="1" />
                </el-select>
              </el-form-item>
            </el-col>
            <!--platform-->
            <el-col :span="6">
              <el-form-item label="平台">
                <el-input v-model="queryForm.platform" clearable />
              </el-form-item>
            </el-col>

            <!--version-->
            <el-col :span="6">
              <el-form-item label="版本">
                <el-input v-model="queryForm.version" clearable />
              </el-form-item>
            </el-col>

            <!--屏幕尺寸-->
            <el-col :span="6">
              <el-form-item label="屏幕尺寸">
                <el-input v-model="queryForm.lcd" clearable />
              </el-form-item>
            </el-col>

            <!--PBM负责人-->
            <el-col :span="6">
              <el-form-item :label="$t('FdData.pbmOwner')">
                <el-select
                  v-model="queryForm.pbmOwner"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getPbmUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.gcmFunction + ' ' + item.team }}
                    </span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <!--创建人-->
            <el-col :span="6">
              <el-form-item label="创建人">
                <el-input v-model="queryForm.createUser" clearable />
                <!-- <el-select
                  v-model="queryForm.createUser"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.team }}</span>
                 </el-option>
                </el-select> -->
              </el-form-item>
            </el-col>
            <!--修改人-->
            <el-col :span="6">
              <el-form-item label="修改人">
                <el-input v-model="queryForm.modifyUser" clearable />
                <!-- <el-select
                  v-model="queryForm.modifyUser"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.team }}</span>
                  </el-option>
                </el-select> -->
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </template>
    </BaseFunc>

    <!--报价FD数据表格-->
    <BaseTable
      :is-requesting="isRequesting"
      :page-number.sync="pageNumber"
      :page-size.sync="pageSize"
      :table-data="tableData"
      :total="total"
      @query="query"
    >
      <!-- 左浮动 -->
      <template slot="header">
        <!--序号列-->
        <el-table-column align="center" fixed :label="$t('table.NO')" min-width="60px">
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
      </template>

      <!-- 默认内容 -->
      <template>
        <!--rfqId列-->
        <el-table-column
          align="center"
          label="RFQ ID"
          min-width="200px"
          prop="rfqId"
          show-overflow-tooltip
          sortable
        />
        <!--rfq名称列-->
        <el-table-column
          align="center"
          label="RFQ名称"
          min-width="200px"
          prop="rfqName"
          show-overflow-tooltip
          sortable
        />
        <!--bu类型列-->
        <el-table-column
          align="center"
          :label="$t('FdData.bu')"
          min-width="100px"
          prop="bu"
          sortable
        />
        <!--solution列-->
        <el-table-column
          align="center"
          label="Solution"
          min-width="250px"
          prop="solution"
          show-overflow-tooltip
          sortable
        />
        <!--tempmodel列-->
        <el-table-column
          align="center"
          label="Temp-Model"
          min-width="250px"
          prop="tempModel"
          show-overflow-tooltip
          sortable
        />
        <!--tempModelNumber列-->
        <el-table-column
          align="center"
          label="Temp-Model-Number"
          min-width="250px"
          prop="tempModelNumber"
          show-overflow-tooltip
          sortable
        />
        <!--平台列-->
        <el-table-column align="center" label="平台" min-width="200px" prop="platform" sortable />
        <!--版本列-->
        <el-table-column align="center" label="版本" min-width="200px" prop="version" sortable />

        <!--屏幕尺寸列-->
        <el-table-column align="center" label="屏幕尺寸" min-width="200px" prop="lcd" sortable />

        <!-- description列 -->
        <el-table-column
          align="center"
          label="描述"
          min-width="200px"
          prop="description"
          sortable
        />

        <!--专案PBM负责人列-->
        <el-table-column align="center" :label="$t('FdData.pbmOwner')" min-width="100px">
          <template slot-scope="scope">
            <span>
              {{ $store.getters['user/getUserNameById'](scope.row.pbmOwner) || $t('result.none') }}
            </span>
          </template>
        </el-table-column>

        <!--创建时间-->
        <el-table-column
          align="center"
          :label="$t('Cbom.createTime')"
          min-width="200px"
          prop="createTime"
          sortable
        />

        <!--修改人-->
        <el-table-column align="center" :label="$t('Cbom.modifyUser')" min-width="200px" sortable>
          <template slot-scope="scope">
            <span>{{ $store.getters['user/getUserNameById'](scope.row.modifyUser) }}</span>
          </template>
        </el-table-column>

        <!--修改时间-->
        <el-table-column
          align="center"
          :label="$t('Cbom.modifyTime')"
          min-width="200px"
          prop="modifyTime"
          sortable
        />
      </template>

      <!-- 右浮动 -->
      <template slot="end">
        <!--操作列-->
        <el-table-column
          align="center"
          fixed="right"
          :label="$t('table.operate')"
          min-width="140px"
        >
          <template slot-scope="scope">
            <el-button
              v-if="$hasPer('view')"
              size="mini"
              type="text"
              @click="rowView(scope.$index, scope.row)"
            >
              <i class="el-icon-view el-icon--right"></i>
              {{ $t('button.view') }}
            </el-button>
            <el-button
              v-if="$hasPer('assign')"
              :disabled="scope.row.isAssigned"
              size="mini"
              type="text"
              @click="rowAssign(scope.$index, scope.row)"
            >
              <i class="el-icon-guide el-icon--right"></i>
              {{ $t('button.assign') }}
            </el-button>
          </template>
        </el-table-column>
      </template>
    </BaseTable>

    <!--查看对话框-->
    <BaseDialog
      v-if="viewDialogVisible"
      custom-class="mini-head-dialog"
      :fullscreen="true"
      :show-close="false"
      :visible.sync="viewDialogVisible"
    >
      <RfqTabView
        v-if="viewDialogVisible"
        :input-data="currentEditRow"
        :visible.sync="viewDialogVisible"
      />
    </BaseDialog>

    <!--分配对话框-->
    <BaseDialog
      v-if="assignDialogVisible"
      custom-class="mini-head-dialog"
      :fullscreen="true"
      :show-close="false"
      :visible.sync="assignDialogVisible"
    >
      <RfqTabAssign
        v-if="assignDialogVisible"
        :input-data="currentEditRow"
        :visible.sync="assignDialogVisible"
        @cancel="afterEditSave"
      />
    </BaseDialog>
  </BaseWrap>
</template>
<script>
import RfqTabView from './components/RfqTabView'
import RfqTabAssign from './components/RfqTabAssign'
import { RfqPageListToAssign } from '@/api/rfq/rfq'
import { fileExportFdAssign } from '@/api/quote/file-export'

export default {
  name: 'RfqAssign',
  components: { RfqTabView, RfqTabAssign },
  data() {
    return {
      // 正在查询
      isRequesting: false,
      // 高级查询选项抽屉弹出标识
      advanceOptionDrawer: false,
      // 页码
      pageNumber: 1,
      // 页展示行数
      pageSize: 10,
      // 总行数
      total: 0,
      // 表格数据
      tableData: [],
      // 查询表单对象
      queryForm: {
        fdId: '',
        version: '',
        fdName: '',
        fdDesc: '',
        projectName: '',
        model: '',
        modelName: '',
        modelDesc: '',
        baseProjectId: '',
        baseModel: '',
        baseConfig: '',
        expiresDay: '',
        isReceived: '',
        receivedTime: '',
        meOwner: '',
        eeOwner: '',
        pkgOwner: '',
        isAssigned: '',
        assignedTime: '',
        isComplete: '',
        completeTime: '',
        createPost: '',
        createUser: '',
        createTime: '',
        modifyPost: '',
        modifyUser: '',
        modifyTime: ''
      },

      // 查看对话框可见标识
      viewDialogVisible: false,
      // 分配对话框可见标识
      assignDialogVisible: false,
      // 当前编辑行的数据
      currentEditRow: {}
    }
  },
  mounted() {
    this.pageDataInit()
  },
  methods: {
    /* 页面数据初始化*/
    pageDataInit() {
      this.query()
    },
    /* 查询表格数据*/
    async query() {
      try {
        this.isRequesting = true
        this.advanceOptionDrawer = false
        const res = await RfqPageListToAssign({
          pageSize: this.pageSize,
          pageNumber: this.pageNumber,
          pageCondition: this.queryForm
        })
        this.tableData = res.data.list
        this.total = res.data.total
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    /* 行记录查看*/
    rowView(index, row) {
      this.currentEditRow = row
      this.viewDialogVisible = true
    },
    /* 行记录分配*/
    rowAssign(index, row) {
      this.currentEditRow = row
      this.assignDialogVisible = true
    },
    afterEditSave() {
      this.pageDataInit()
      this.assignDialogVisible = false
    },
    // 下载
    async rowDown(index, row) {
      try {
        await this.$confirmBox(this.$t('button.down'), 'success')
        this.isRequesting = true
        const res = await fileExportFdAssign(
          { fdId: row.fdId, version: row.version },
          { downExcelFile: true, msgSuccess: true, msgError: true }
        )
        await this.$downFile(res)
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    }
  }
}
</script>
